package c.c.b.a.b.a.h;

import c.c.b.a.a.e;
import c.c.b.a.a.g;
import c.c.b.a.a.h;
import c.c.b.a.a.o;
import c.c.b.a.a.r;
import c.c.b.a.a.w;
import com.huawei.hms.analytics.core.crypto.AesCipher.AesLen;
import com.pgl.sys.ces.out.ISdkLite;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Logger;

/* compiled from: Hpack */
public final class d {
    public static final c[] a;
    public static final Map<h, Integer> b;

    /* compiled from: Hpack */
    public static final class a {
        public final List<c> a = new ArrayList();
        public final g b;
        public final int c;
        public int d;
        public c[] e = new c[8];
        public int f = 7;
        public int g = 0;
        public int h = 0;

        public a(int i, w wVar) {
            this.c = i;
            this.d = i;
            Logger logger = o.a;
            this.b = new r(wVar);
        }

        public final int a(int i) {
            int i2 = 0;
            if (i > 0) {
                int i3;
                c[] cVarArr;
                int length = this.e.length;
                while (true) {
                    length--;
                    i3 = this.f;
                    if (length < i3 || i <= 0) {
                        cVarArr = this.e;
                        System.arraycopy(cVarArr, i3 + 1, cVarArr, (i3 + 1) + i2, this.g);
                        this.f += i2;
                    } else {
                        c[] cVarArr2 = this.e;
                        i -= cVarArr2[length].c;
                        this.h -= cVarArr2[length].c;
                        this.g--;
                        i2++;
                    }
                }
                cVarArr = this.e;
                System.arraycopy(cVarArr, i3 + 1, cVarArr, (i3 + 1) + i2, this.g);
                this.f += i2;
            }
            return i2;
        }

        public int b(int i, int i2) throws IOException {
            i &= i2;
            if (i < i2) {
                return i;
            }
            i = 0;
            while (true) {
                int h = this.b.h() & ISdkLite.REGION_UNSET;
                if ((h & AesLen.ROOTKEY_COMPONET_LEN) == 0) {
                    return i2 + (h << i);
                }
                i2 += (h & 127) << i;
                i += 7;
            }
        }

        public final void c(int i, c cVar) {
            this.a.add(cVar);
            int i2 = cVar.c;
            if (i != -1) {
                i2 -= this.e[(this.f + 1) + i].c;
            }
            int i3 = this.d;
            if (i2 > i3) {
                f();
                return;
            }
            i3 = a((this.h + i2) - i3);
            if (i == -1) {
                i = this.g + 1;
                c[] cVarArr = this.e;
                if (i > cVarArr.length) {
                    c[] cVarArr2 = new c[(cVarArr.length * 2)];
                    System.arraycopy(cVarArr, 0, cVarArr2, cVarArr.length, cVarArr.length);
                    this.f = this.e.length - 1;
                    this.e = cVarArr2;
                }
                i = this.f;
                this.f = i - 1;
                this.e[i] = cVar;
                this.g++;
            } else {
                this.e[(((this.f + 1) + i) + i3) + i] = cVar;
            }
            this.h += i2;
        }

        public final int d(int i) {
            return (this.f + 1) + i;
        }

        public h e() throws IOException {
            int h = this.b.h() & ISdkLite.REGION_UNSET;
            Object obj = (h & AesLen.ROOTKEY_COMPONET_LEN) == AesLen.ROOTKEY_COMPONET_LEN ? 1 : null;
            h = b(h, 127);
            if (obj == null) {
                return this.b.c((long) h);
            }
            s sVar = s.d;
            byte[] l = this.b.l((long) h);
            Objects.requireNonNull(sVar);
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            c.c.b.a.b.a.h.s.a aVar = sVar.a;
            int i = 0;
            int i2 = 0;
            for (byte b : l) {
                i = (i << 8) | (b & ISdkLite.REGION_UNSET);
                i2 += 8;
                while (i2 >= 8) {
                    int i3 = i2 - 8;
                    aVar = aVar.a[(i >>> i3) & ISdkLite.REGION_UNSET];
                    if (aVar.a == null) {
                        byteArrayOutputStream.write(aVar.b);
                        i2 -= aVar.c;
                        aVar = sVar.a;
                    } else {
                        i2 = i3;
                    }
                }
            }
            while (i2 > 0) {
                c.c.b.a.b.a.h.s.a aVar2 = aVar.a[(i << (8 - i2)) & ISdkLite.REGION_UNSET];
                if (aVar2.a != null || aVar2.c > i2) {
                    break;
                }
                byteArrayOutputStream.write(aVar2.b);
                i2 -= aVar2.c;
                aVar = sVar.a;
            }
            return h.e(byteArrayOutputStream.toByteArray());
        }

        public final void f() {
            Arrays.fill(this.e, null);
            this.f = this.e.length - 1;
            this.g = 0;
            this.h = 0;
        }

        public final h g(int i) {
            int i2 = 1;
            if (i < 0 || i > d.a.length - 1) {
                i2 = 0;
            }
            if (i2 != 0) {
                return d.a[i].a;
            }
            return this.e[d(i - d.a.length)].a;
        }
    }

    /* compiled from: Hpack */
    public static final class b {
        public final e a;
        public int b = Integer.MAX_VALUE;
        public boolean c;
        public int d = 4096;
        public c[] e = new c[8];
        public int f = 7;
        public int g = 0;
        public int h = 0;

        public b(e eVar) {
            this.a = eVar;
        }

        public final void a() {
            Arrays.fill(this.e, null);
            this.f = this.e.length - 1;
            this.g = 0;
            this.h = 0;
        }

        public void b(int i, int i2, int i3) {
            if (i < i2) {
                this.a.h0(i | i3);
                return;
            }
            this.a.h0(i3 | i2);
            i -= i2;
            while (i >= AesLen.ROOTKEY_COMPONET_LEN) {
                this.a.h0(AesLen.ROOTKEY_COMPONET_LEN | (i & 127));
                i >>>= 7;
            }
            this.a.h0(i);
        }

        public void c(h hVar) throws IOException {
            Objects.requireNonNull(s.d);
            long j = 0;
            long j2 = 0;
            for (int i = 0; i < hVar.v(); i++) {
                j2 += (long) s.c[hVar.a(i) & ISdkLite.REGION_UNSET];
            }
            if (((int) ((j2 + 7) >> 3)) < hVar.v()) {
                e eVar = new e();
                Objects.requireNonNull(s.d);
                int i2 = 0;
                for (int i3 = 0; i3 < hVar.v(); i3++) {
                    int a = hVar.a(i3) & ISdkLite.REGION_UNSET;
                    int i4 = s.b[a];
                    byte b = s.c[a];
                    j = (j << b) | ((long) i4);
                    i2 += b;
                    while (i2 >= 8) {
                        i2 -= 8;
                        eVar.h0((int) (j >> i2));
                    }
                }
                if (i2 > 0) {
                    eVar.h0((int) ((j << (8 - i2)) | ((long) (ISdkLite.REGION_UNSET >>> i2))));
                }
                hVar = eVar.z0();
                b(hVar.a.length, 127, AesLen.ROOTKEY_COMPONET_LEN);
                e eVar2 = this.a;
                Objects.requireNonNull(eVar2);
                byte[] bArr = hVar.a;
                eVar2.t0(bArr, 0, bArr.length);
                return;
            }
            b(hVar.v(), 127, 0);
            e eVar3 = this.a;
            Objects.requireNonNull(eVar3);
            hVar.k(eVar3);
        }

        public final void d(c cVar) {
            int i = cVar.c;
            int i2 = this.d;
            if (i > i2) {
                a();
                return;
            }
            f((this.h + i) - i2);
            i2 = this.g + 1;
            c[] cVarArr = this.e;
            if (i2 > cVarArr.length) {
                c[] cVarArr2 = new c[(cVarArr.length * 2)];
                System.arraycopy(cVarArr, 0, cVarArr2, cVarArr.length, cVarArr.length);
                this.f = this.e.length - 1;
                this.e = cVarArr2;
            }
            i2 = this.f;
            this.f = i2 - 1;
            this.e[i2] = cVar;
            this.g++;
            this.h += i;
        }

        public void e(List<c> list) throws IOException {
            int i;
            if (this.c) {
                i = this.b;
                if (i < this.d) {
                    b(i, 31, 32);
                }
                this.c = false;
                this.b = Integer.MAX_VALUE;
                b(this.d, 31, 32);
            }
            i = list.size();
            for (int i2 = 0; i2 < i; i2++) {
                int intValue;
                int i3;
                c cVar = (c) list.get(i2);
                h u = cVar.a.u();
                h hVar = cVar.b;
                Integer num = (Integer) d.b.get(u);
                if (num != null) {
                    intValue = num.intValue() + 1;
                    if (intValue > 1 && intValue < 8) {
                        c[] cVarArr = d.a;
                        if (c.c.b.a.b.a.e.r(cVarArr[intValue - 1].b, hVar)) {
                            i3 = intValue;
                        } else if (c.c.b.a.b.a.e.r(cVarArr[intValue].b, hVar)) {
                            i3 = intValue;
                            intValue++;
                        }
                    }
                    i3 = intValue;
                    intValue = -1;
                } else {
                    intValue = -1;
                    i3 = -1;
                }
                if (intValue == -1) {
                    int length = this.e.length;
                    for (int i4 = this.f + 1; i4 < length; i4++) {
                        if (c.c.b.a.b.a.e.r(this.e[i4].a, u)) {
                            if (c.c.b.a.b.a.e.r(this.e[i4].b, hVar)) {
                                intValue = d.a.length + (i4 - this.f);
                                break;
                            } else if (i3 == -1) {
                                i3 = (i4 - this.f) + d.a.length;
                            }
                        }
                    }
                }
                if (intValue != -1) {
                    b(intValue, 127, AesLen.ROOTKEY_COMPONET_LEN);
                } else if (i3 == -1) {
                    this.a.h0(64);
                    c(u);
                    c(hVar);
                    d(cVar);
                } else {
                    h hVar2 = c.d;
                    Objects.requireNonNull(u);
                    if (!u.l(0, hVar2, 0, hVar2.v()) || c.i.equals(u)) {
                        b(i3, 63, 64);
                        c(hVar);
                        d(cVar);
                    } else {
                        b(i3, 15, 0);
                        c(hVar);
                    }
                }
            }
        }

        public final int f(int i) {
            int i2 = 0;
            if (i > 0) {
                int i3;
                c[] cVarArr;
                int length = this.e.length;
                while (true) {
                    length--;
                    i3 = this.f;
                    if (length < i3 || i <= 0) {
                        cVarArr = this.e;
                        System.arraycopy(cVarArr, i3 + 1, cVarArr, (i3 + 1) + i2, this.g);
                        cVarArr = this.e;
                        length = this.f;
                        Arrays.fill(cVarArr, length + 1, (length + 1) + i2, null);
                        this.f += i2;
                    } else {
                        c[] cVarArr2 = this.e;
                        i -= cVarArr2[length].c;
                        this.h -= cVarArr2[length].c;
                        this.g--;
                        i2++;
                    }
                }
                cVarArr = this.e;
                System.arraycopy(cVarArr, i3 + 1, cVarArr, (i3 + 1) + i2, this.g);
                cVarArr = this.e;
                length = this.f;
                Arrays.fill(cVarArr, length + 1, (length + 1) + i2, null);
                this.f += i2;
            }
            return i2;
        }
    }

    static {
        r0 = new c[61];
        String str = "";
        int i = 0;
        r0[0] = new c(c.i, str);
        h hVar = c.f;
        r0[1] = new c(hVar, "GET");
        r0[2] = new c(hVar, "POST");
        hVar = c.g;
        r0[3] = new c(hVar, "/");
        r0[4] = new c(hVar, "/index.html");
        hVar = c.h;
        r0[5] = new c(hVar, "http");
        r0[6] = new c(hVar, "https");
        hVar = c.e;
        r0[7] = new c(hVar, "200");
        r0[8] = new c(hVar, "204");
        r0[9] = new c(hVar, "206");
        r0[10] = new c(hVar, "304");
        r0[11] = new c(hVar, "400");
        r0[12] = new c(hVar, "404");
        r0[13] = new c(hVar, "500");
        r0[14] = new c("accept-charset", str);
        r0[15] = new c("accept-encoding", "gzip, deflate");
        r0[16] = new c("accept-language", str);
        r0[17] = new c("accept-ranges", str);
        r0[18] = new c("accept", str);
        r0[19] = new c("access-control-allow-origin", str);
        r0[20] = new c("age", str);
        r0[21] = new c("allow", str);
        r0[22] = new c("authorization", str);
        r0[23] = new c("cache-control", str);
        r0[24] = new c("content-disposition", str);
        r0[25] = new c("content-encoding", str);
        r0[26] = new c("content-language", str);
        r0[27] = new c("content-length", str);
        r0[28] = new c("content-location", str);
        r0[29] = new c("content-range", str);
        r0[30] = new c("content-type", str);
        r0[31] = new c("cookie", str);
        r0[32] = new c("date", str);
        r0[33] = new c("etag", str);
        r0[34] = new c("expect", str);
        r0[35] = new c("expires", str);
        r0[36] = new c("from", str);
        r0[37] = new c("host", str);
        r0[38] = new c("if-match", str);
        r0[39] = new c("if-modified-since", str);
        r0[40] = new c("if-none-match", str);
        r0[41] = new c("if-range", str);
        r0[42] = new c("if-unmodified-since", str);
        r0[43] = new c("last-modified", str);
        r0[44] = new c("link", str);
        r0[45] = new c("location", str);
        r0[46] = new c("max-forwards", str);
        r0[47] = new c("proxy-authenticate", str);
        r0[48] = new c("proxy-authorization", str);
        r0[49] = new c("range", str);
        r0[50] = new c("referer", str);
        r0[51] = new c("refresh", str);
        r0[52] = new c("retry-after", str);
        r0[53] = new c("server", str);
        r0[54] = new c("set-cookie", str);
        r0[55] = new c("strict-transport-security", str);
        r0[56] = new c("transfer-encoding", str);
        r0[57] = new c("user-agent", str);
        r0[58] = new c("vary", str);
        r0[59] = new c("via", str);
        r0[60] = new c("www-authenticate", str);
        a = r0;
        LinkedHashMap linkedHashMap = new LinkedHashMap(r0.length);
        while (true) {
            r0 = a;
            if (i < r0.length) {
                if (!linkedHashMap.containsKey(r0[i].a)) {
                    linkedHashMap.put(r0[i].a, Integer.valueOf(i));
                }
                i++;
            } else {
                b = Collections.unmodifiableMap(linkedHashMap);
                return;
            }
        }
    }

    public static h a(h hVar) throws IOException {
        int v = hVar.v();
        int i = 0;
        while (i < v) {
            byte a = hVar.a(i);
            if (a < (byte) 65 || a > (byte) 90) {
                i++;
            } else {
                StringBuilder g = c.b.a.a.a.g("PROTOCOL_ERROR response malformed: mixed case name: ");
                g.append(hVar.j());
                throw new IOException(g.toString());
            }
        }
        return hVar;
    }
}
